﻿using Com.Lancetinc.Evs.Services;
using System;
using System.Windows;
using System.Windows.Media;
using Com.Lancetinc.Evs.Helpers;

namespace Com.Lancetinc.Evs.Controls
{
    /// <summary>
    /// 报告页视频播放+截图
    /// </summary>
    public partial class ReportVideo2ImageUserControl
    {
        private ExperInfo mExper;

        public event EventHandler<bool> OnFullScreenChanged;

        public event EventHandler OnCannotDisplayFully;

        public void SetExper(ExperInfo exper)
        {
            mExper = exper;
            CtrlVideoPlay.SetExper(exper);
            CtrlCapturedImage.SetExper(exper);
        }

        public ReportVideo2ImageUserControl()
        {
            InitializeComponent();
            this.Loaded += ReportVideo2ImageUserControl_Loaded;
        }

        private void ReportVideo2ImageUserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.ActualWidth < 380)
            {
                var dpi = VisualTreeHelper.GetDpi(this);
                if (dpi.DpiScaleX > 1)
                {
                    OnCannotDisplayFully?.Invoke(this, EventArgs.Empty);
                    // 视频播放组件不能完整显示，建议屏幕调整分辨率或者缩放比例
                    WpfHelper.ExecLater(() =>
                    {
                        MessageHelper.ShowByMsgId("ReportVideo2ImageUserControl.CannotDisplayFully");
                    }, 100);
                }
            }
        }

        /// <summary>
        /// 显示已截屏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CtrlVideoPlay_OnRequireShowCapturedScreen(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 全屏切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="isFullScreen"></param>
        private void CtrlVideoPlay_OnFullScreenChanged(object sender, bool isFullScreen)
        {
            if (isFullScreen)
            {
                ColCapturedImage.Height = new GridLength(0);
            }
            else
            {
                ColCapturedImage.Height = new GridLength(1, GridUnitType.Star);
            }

            OnFullScreenChanged?.Invoke(this, isFullScreen);
        }

        /// <summary>
        /// 截图成功
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="imageName"></param>
        private void CtrlVideoPlay_OnVideoImageCaptured(object sender, string imageName)
        {
            CtrlCapturedImage.SetExper(mExper);
            CtrlCapturedImage.ShowImage(imageName);
        }
    }
}
